using Godot;

namespace PaintAWorld.Gd.Dialogs
{
    public partial class CommandDialog : Dialog
	{
		[Export]
		public LineEdit commandEdit;
		[Export]
		public Button submitButton;

		public override void _Ready()
		{
			commandEdit.GrabFocus();
		}

		public override void _Input(InputEvent e)
		{
			if (e is InputEventKey ke && ke.Pressed && ke.Keycode == Key.Enter)
			{
				SubmitCommandAndClose();
			}
		}

		public void SubmitCommandAndClose()
		{
			Manager.Client.SubmitCommand(commandEdit.Text);
			Close();
		}
	}
}
